/**   
 * @Title: MeetPriceServiceImpl.java 
 * @Package com.hanyong.admin.service.meetPrice 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author Li  
 * @date 2018年6月7日 上午11:15:30 
 * @version V1.0   
 */
package com.hyfrogx.modules.zoom.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hyfrogx.common.exception.MyException;
import com.hyfrogx.common.utils.RedisUtils;
import com.hyfrogx.modules.app.utils.FrogConstant;
import com.hyfrogx.modules.zoom.param.ZoomJoinPrice;
import com.hyfrogx.modules.zoom.service.MeetJoinPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/** 
 * @ClassName: MeetPriceServiceImpl 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author Li
 * @date 2018年6月7日 上午11:15:30 
 *  
 */
@Service(value = MeetJoinPriceService.name)
public class MeetJoinPriceServiceImpl implements MeetJoinPriceService {

	static ZoomJoinPrice zoomJoinPirceObject = null;

	@Autowired
	RedisUtils redisUtils;

	String meetJoinprice = null;

	@Override
	public void init() {
		//通过key获取对象
		meetJoinprice = redisUtils.get(FrogConstant.RedisKey.FIX_BASIC_JOIN_PRICE);

		if(meetJoinprice == null){
			ZoomJoinPrice zoomJoinPirce = new ZoomJoinPrice();
			// 25方
			zoomJoinPirce.setSmallTypeZero(1);
			zoomJoinPirce.setSmallTypeOne(2);
			zoomJoinPirce.setSmallTypeTwo(3);
			zoomJoinPirce.setSmallTypeThree(4);
			zoomJoinPirce.setSmallTypeFour(5);
			zoomJoinPirce.setSmallTypeFive(6);
			zoomJoinPirce.setSmallTypeSix(7);
			zoomJoinPirce.setSmallTypeSeven(8);
			zoomJoinPirce.setSmallTypeEight(9);
			zoomJoinPirce.setSmallTypeEight(10);
			zoomJoinPirce.setSmallTypeTen(11);
			zoomJoinPirce.setSmallTypeEle(12);
			// 50
			zoomJoinPirce.setCenterTypeZero(13);
			zoomJoinPirce.setCenterTypeOne(14);
			zoomJoinPirce.setCenterTypeOne(15);
			zoomJoinPirce.setCenterTypeTwo(16);
			zoomJoinPirce.setCenterTypeThree(17);
			zoomJoinPirce.setCenterTypeFour(18);
			zoomJoinPirce.setCenterTypeFive(19);
			zoomJoinPirce.setCenterTypeSix(20);
			zoomJoinPirce.setCenterTypeSeven(21);
			zoomJoinPirce.setCenterTypeEight(22);
			zoomJoinPirce.setCenterTypeTen(23);
			zoomJoinPirce.setCenterTypeEle(24);
			// 100
			zoomJoinPirce.setBigTypeZero(0);
			zoomJoinPirce.setBigTypeOne(0);
			zoomJoinPirce.setBigTypeTwo(0);
			zoomJoinPirce.setBigTypeThree(0);
			zoomJoinPirce.setBigTypeFour(0);
			zoomJoinPirce.setBigTypeFive(0);
			zoomJoinPirce.setBigTypeSix(0);
			zoomJoinPirce.setBigTypeSeven(0);
			zoomJoinPirce.setBigTypeEight(0);
			zoomJoinPirce.setBigTypeTen(0);
			zoomJoinPirce.setBigTypeEle(0);
			// 500
			zoomJoinPirce.setOversizeTypeZero(0);
			zoomJoinPirce.setOversizeTypeOne(0);
			zoomJoinPirce.setOversizeTypeTwo(0);
			zoomJoinPirce.setOversizeTypeThree(0);
			zoomJoinPirce.setOversizeTypeFour(0);
			zoomJoinPirce.setOversizeTypeFive(0);
			zoomJoinPirce.setOversizeTypeSix(0);
			zoomJoinPirce.setOversizeTypeSeven(0);
			zoomJoinPirce.setOversizeTypeEight(0);
			zoomJoinPirce.setOversizeTypeTen(0);
			zoomJoinPirce.setOversizeTypeEle(0);
			// 200
			zoomJoinPirce.setTwohundredTypeZero(0);
			zoomJoinPirce.setTwohundredTypeOne(0);
			zoomJoinPirce.setTwohundredTypeTwo(0);
			zoomJoinPirce.setTwohundredTypeThree(0);
			zoomJoinPirce.setTwohundredTypeFour(0);
			zoomJoinPirce.setTwohundredTypeFive(0);
			zoomJoinPirce.setTwohundredTypeSix(0);
			zoomJoinPirce.setTwohundredTypeSeven(0);
			zoomJoinPirce.setTwohundredTypeEight(0);
			zoomJoinPirce.setTwohundredTypeTen(0);
			zoomJoinPirce.setTwohundredTypeEle(0);
			// 300
			zoomJoinPirce.setThreeTypeZero(0);
			zoomJoinPirce.setThreeTypeOne(0);
			zoomJoinPirce.setThreeTypeTwo(0);
			zoomJoinPirce.setThreeTypeThree(0);
			zoomJoinPirce.setThreeTypeFour(0);
			zoomJoinPirce.setThreeTypeFive(0);
			zoomJoinPirce.setThreeTypeSix(0);
			zoomJoinPirce.setThreeTypeSeven(0);
			zoomJoinPirce.setThreeTypeEight(0);
			zoomJoinPirce.setThreeTypeTen(0);
			zoomJoinPirce.setThreeTypeEle(0);
			redisUtils.set(FrogConstant.RedisKey.FIX_BASIC_JOIN_PRICE, zoomJoinPirce);
			zoomJoinPirceObject = zoomJoinPirce;
		}else{
			JSONObject jsonObject  = JSONObject.parseObject(meetJoinprice);
			zoomJoinPirceObject = (ZoomJoinPrice) jsonObject.toJavaObject(ZoomJoinPrice.class);
		}
		editMeetPrice(zoomJoinPirceObject);
	}

	@Override
	public Integer editMeetPrice(ZoomJoinPrice zoomJoinPrice) throws MyException {
		// TODO Auto-generated method stub
		zoomJoinPirceObject = zoomJoinPrice;
		redisUtils.set(FrogConstant.RedisKey.FIX_BASIC_JOIN_PRICE, zoomJoinPrice);
		return 1;
	}

	@Override
	public Integer getMeetPriceByTime(String field) throws MyException {
		JSONObject jsonObject  = JSONObject.parseObject(meetJoinprice);
		int result = jsonObject.getInteger(field);
		return result;
	}

	@Override
	public ZoomJoinPrice getMeetPriceObject() throws MyException {
		// TODO Auto-generated method stub
		return zoomJoinPirceObject;
	}
	
}
